﻿Imports SS
Imports SS.Databases
Imports SS.Databases.Connecter
Imports SS.ApplicationBlock

Public Class SystemConfig

	Public Shared Function LoadValue(ByVal key As String) As String
		Using connOraSelect As New DBOracle(Common.Utility.ConnectString, False)
			Return connOraSelect.ExecuteScalar("SELECT VALUE FROM " & Common.Utility.Schema & ".RNWM_CONFIG WHERE KEY = '" & key & "'")
		End Using
	End Function

    Public Shared Function GetRVBalance(ByVal effectDate As Date, ByVal incomeMyself As Decimal) As String
        Dim sb As New Text.StringBuilder
        sb.AppendLine(" SELECT NVL(RV_BALANCE,1) ")
        sb.AppendLine(" FROM " & Common.Utility.Schema & ".RNWM_CONFIG_CALCULATE_RV RV ")
        sb.AppendLine(" INNER JOIN(" & Common.Utility.Schema & ".RNWM_CONFIG_CALCULATE_RV_DET RVD) ON RV.CALCULATE_RV_ID=RVD.CALCULATE_RV_ID ")
        sb.AppendLine(" WHERE TO_DATE('" & effectDate.ToString("dd/MM/yyyy", New Globalization.CultureInfo("en-GB")) & "','dd/mm/yyyy') ")
        sb.AppendLine(" BETWEEN RV.RV_START_DATE And RV.RV_END_DATE ")
        sb.AppendLine(" AND " & incomeMyself)
        sb.AppendLine(" BETWEEN RVD.RV_START AND RVD.RV_END ")
        Using connOraSelect As New DBOracle(Common.Utility.ConnectString, False)
            Return connOraSelect.ExecuteScalar(sb.ToString)
        End Using
    End Function

End Class
